﻿Imports System.Resources
Imports System.Globalization
Imports System.Reflection

Imports BUS
Imports DTO

Public Class frmTacGia

    ReadOnly culInfoMgr As CommonLibrary

    Public Sub New(ByVal culInfoMgr As CommonLibrary)
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        Me.culInfoMgr = culInfoMgr
        AddHandler culInfoMgr.OnCultureInfoChanges, AddressOf CultureInfiHasChange
    End Sub

    Private Sub CultureInfiHasChange(ByVal sender As Object, ByVal e As EventArgs)
        Try
            SetUI()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub SetUI()
        Dim culInfo As CultureInfo = culInfoMgr.getCultureinfo
        Dim rm As New ResourceManager("Gui.frmTacGia", GetType(frmThemSachCu).Assembly)
        Me.Text = rm.GetString("frmTacGiaText", culInfo)
        '   lblTenTacGia.Text = rm.GetString("lblTenTacGiaText", culInfo)
        btnThemTacGia.Text = rm.GetString("btnThemTacGiaText", culInfo)
        btnXoa.Text = rm.GetString("btnXoaText", culInfo)
    End Sub

    Private Sub btnThemTacGia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemTacGia.Click

        If KiemTra() = False Then
            Exit Sub
        End If
        Try
            Dim tg As New TacGiaDTO
            Dim tacgia As New TacGiaBUS
            tg.LayTenTacGia = LCase(txtTentacGia.Text.Trim)
            tacgia.ThemTacGia(tg)
            ThongBaoTC()
            Me.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Public Sub ThongBaoTC()
        Dim ngon As CultureInfo = culInfoMgr.getCultureinfo
        If ngon.Name = "vi-VN" Then
            MessageBox.Show("Thêm Thành Công.", "Thông Báo", MessageBoxButtons.OK)
        Else
            MessageBox.Show("Add Success.", "Success", MessageBoxButtons.OK)
        End If

    End Sub

    Private Sub frmTacGia_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            SetUI()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        '    LoadSize()
        LoadTacGia()
    End Sub

    Public Function KiemTra() As Boolean
        Dim ngon As CultureInfo = culInfoMgr.getCultureinfo
        If ngon.Name = "vi-VN" Then
            If txtTentacGia.Text = "" Then
                MessageBox.Show("Tác giả không được bỏ trống", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return False
            End If
        Else
            If txtTentacGia.Text = "" Then
                MessageBox.Show("Author is not empty", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Return False
            End If
        End If
        Return True

    End Function

    Dim loai As Integer = frmLogin.loai

    Public Sub LoadSize()
        If loai = 1 Then
            Me.Width = 419
            Me.Height = 125
            btnXoa.Visible = False
        Else
            Me.Width = 497
            Me.Height = 365
        End If
    End Sub

    Public Sub LoadTacGia()
        Dim dt As New DataTable
        Dim tacgia As New TacGiaBUS
        dt = tacgia.LayTacGia()
        DataGridView_TacGia.DataSource = dt
    End Sub

    Public Function HoiXoa() As DialogResult
        Dim xoa As DialogResult
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            xoa = MessageBox.Show("Bạn Muốn Xóa ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        Else
            xoa = MessageBox.Show(" Are You Delete .", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            Return xoa
        End If
    End Function

    Public Sub XoaThanhCong()
        Dim NgonNguHientien As CultureInfo = culInfoMgr.getCultureinfo
        If NgonNguHientien.Name = "vi-VN" Then
            MessageBox.Show("Xóa Thành Công.", "Thông Báo", MessageBoxButtons.OK)
        Else
            MessageBox.Show("Delete Success.", "Success", MessageBoxButtons.OK)
        End If
    End Sub

    'Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
    '    If DataGridView_TacGia.SelectedRows.Count = 0 Then
    '        frmMain.Xoaloi()
    '        Exit Sub
    '    End If

    '    Try
    '        If HoiXoa() = Windows.Forms.DialogResult.Yes Then
    '            If (DataGridView_TacGia.SelectedRows.Count > 0) Then
    '                For i = 0 To DataGridView_TacGia.SelectedRows.Count - 1
    '                    Dim tac As New TacGiaDTO

    '                    Dim s As New TacGiaBUS
    '                    tac.LayIdTacGia = DataGridView_TacGia.SelectedRows(i).Cells(0).Value
    '                    '    s.XoaTacGia(tac)
    '                Next
    '                XoaThanhCong()
    '                Dim s1 As New TacGiaBUS
    '                DataGridView_TacGia.DataSource = s1.LayTacGia
    '            End If
    '        End If

    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '    End Try
    'End Sub

End Class